<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateCruiseTaskCategoryTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cruise_project_category', function (Blueprint $table) {
            $table->id();
            $table->string('name', 32)->default('')->comment('分类名称');
            $table->unsignedInteger('pid')->default(0)->comment('父级分类id');
            $table->unsignedTinyInteger('sort')->default(0)->comment('排序 数字大权重大');

            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');
            $table->unsignedTinyInteger('isDeleted')->default(0);
            $table->collation = 'utf8mb4_general_ci';
            $table->comment   = '巡店 - 项目分类';
        });

        $arr = [
            [
                'name' => '新店帮扶',
                'pid'  => 0,
            ],
            [
                'name' => '店面形象',
                'pid'  => 1,
            ],
            [
                'name' => '检查证照',
                'pid'  => 1,
            ],
            [
                'name' => '货品摆放',
                'pid'  => 1,
            ],
        ];

        \App\Models\Cruise\CruiseProjectCategoryModel::query()->insert(collect($arr)->map(function ($item) {
            $item['createdAt'] = $item['updatedAt'] = time();
            return $item;
        })->toArray());
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('cruise_project_category');
    }
}
